package logic

import (
	"context"
	"github.com/zeromicro/go-zero/core/logx"
	"shop_srv/goods"
	"shop_srv/internal/svc"
	"shop_srv/model/redis"
)

type GetGoodsStockLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewGetGoodsStockLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetGoodsStockLogic {
	return &GetGoodsStockLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *GetGoodsStockLogic) GetGoodsStock(in *goods.GetGoodsStockRequest) (*goods.GetGoodsStockResponse, error) {
	//预扣库存长度
	stock := redis.GetStockLength(int(in.GoodsId))
	return &goods.GetGoodsStockResponse{GoodsStatus: int64(stock)}, nil
}
